package com.huitone.gddw.controller.monitoring.sms;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.huitone.gddw.controller.common.CommonController;
import com.huitone.gddw.dao.entity.SmLog;
import com.huitone.gddw.service.monitoring.sms.IPriQueueService;
import com.huitone.gddw.utils.SysLoginUtil;

/**
 * 优先级队列监控
 * @author wuluodan
 *
 */
@Controller
@RequestMapping(value="priQueue")
public class PriQueueController extends CommonController {

	private final static Logger LOGGER = Logger.getLogger(PriQueueController.class);
	
	@Autowired
	private IPriQueueService priQueueService;
	
	/**
	 * 查询
	 * @param request
	 * @return QueryPage
	 */
	@ResponseBody
	@RequestMapping(value="query")
	public List<Map<String, Object>> query(HttpServletRequest request) {
		super.logType = SmLog.LOGTYPE_SELECT;
		super.logContent = "[" + SysLoginUtil.getLoginUserId() + "]查询优先级队列监控";
		List<Map<String, Object>> result = null;
		try {
			result = priQueueService.find(getParams(request));
			if (null == result) {
				result = new ArrayList<>();
			}
		} catch (Exception e) {
			LOGGER.error("查询优先级队列监控信息出现异常：" + e.getMessage(), e);
			super.logResult = SmLog.RESULT_FAIL;
		}
		super.saveSmLog(super.logType, super.logContent, super.logResult);
		return result;
	}
	
	/**
	 * 获取参数信息
	 * @param request
	 * @return Map<String, Object>
	 */
	private Map<String, Object> getParams(HttpServletRequest request) {
		String svrNode = request.getParameter("svrNode");
		String serviceCode = request.getParameter("serviceCode");
		String gateLinkId = request.getParameter("gateLinkId");
		String level = request.getParameter("level");
		
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("svrNode", svrNode);
		params.put("serviceCode", serviceCode);
		params.put("gateLinkId", gateLinkId);
		params.put("level", level);
		return params;
	}
	
}
